﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CoolCode.Linq;
using CoolCode.Entities; 

namespace CoolCode.Web.UI.Controls
{
    public partial class ProductFilter : System.Web.UI.UserControl, IFilterable<Inspection>
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (!IsPostBack)
            {
                cdrCheckDateFr.Value = DateTime.Now.Date.AddMonths(-12);
                cdrCheckDateTo.Value = DateTime.Now.Date;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        #region IFilterable<Inspection> Members

        public IQueryBuilder<Inspection> CreateFilter()
        {
            var qb = QueryBuilder.Create<Inspection>()
                 .Fuzzy(c => c.ProductID, txtProductID.Text)
                 .Fuzzy(c => c.ProductSpec, txtProductSpec.Text)
                 .Between(c => c.CheckDate, cdrCheckDateFr.Value.GetValueOrDefault(), cdrCheckDateTo.Value.GetValueOrDefault());
            return qb;
        }

        #endregion
    }
}